package com.gexin.common.app;

import cn.jpush.api.push.model.audience.Audience;
import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * 极光推送消息构造类
 * @author 肖得明
 * 2017 0818完成基础构造 
 */
public class JpushModel implements Serializable {
	private static final long serialVersionUID = -8333681928742839842L;
	//推送类型
	public static enum PushType { 
		/**内部消息**/
		 inner 
		 /**外部消息**/
		, outer ; }
		
	private String   type;// 事件类型
	private String   title;// 推送标题
	private String   centent;// 推送内容
	private Object   data;// 数据
	private PushType push_type;// 推送类型 inner outer
	private boolean  silent=true;// 是否显示给用户看
	private Audience   audience;//推送类型
	private String jpushid;	
	
	
	/**
	 * 开始推送的方法
	 * @return
	 */
	public void startPush(){
		JpushToolsApi.startPush(this);
	}
	public JpushModel() {
	}

	
	public String getJpushid() {
		return jpushid;
	}

	public void setJpushid(String jpushid) {
		this.jpushid = jpushid;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCentent() {
		return centent;
	}

	public void setCentent(String centent) {
		this.centent = centent;
	}

	public Object getData() {
		return data;
	}
	public String getDataToJson() {
		if(data==null){
			return  "";
		}
		return JSONObject.toJSONString(data);
	}

	public void setData(Object data) {
		this.data = data;
	}

	
	public PushType getPush_type() {
		return push_type;
	}

	public void setPush_type(PushType push_type) {
		this.push_type = push_type;
	}

	public boolean isSilent() {
		return silent;
	}

	public void setSilent(boolean silent) {
		this.silent = silent;
	}

	public Audience getAudience() {
		if(audience==null){
			return Audience.registrationId(getJpushid());
		}
		return audience;
	}

	public void setAudience(Audience audience) {
		this.audience = audience;
	}

	
}
